package cn.e4j.modular.api.controller;

import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ErrorResponseData;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.core.reqres.response.SuccessResponseData;
import cn.e4j.core.util.InvokeUtil;
import cn.e4j.modular.api.service.PjqsService;
import cn.e4j.modular.api.util.ControllerSupport;
import cn.e4j.modular.system.entity.SysUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wenchuan.li on 2018/04/19.
 */
@RestController
@RequestMapping("api/wx/pjqs")
public class PjqsController extends ControllerSupport {

    @Autowired
    private PjqsService pjqsService;

    /**
     * 获取配件签收列表
     *
     * @return
     */
    @RequestMapping(value = "getPjqsList")
    public ResponseData getServiceOrderList(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = new ArrayList<>();
        SysUser currentUser = wapper.getSysUser();
        try {
            inDto.put("MMRVENT", inDto.getString("ENT"));
            inDto.put("MMRS003", currentUser.getORG_ID());//员工编号
            String _type = inDto.getString("_type");
            if (_type.equals("1")) { // 未签收
                list = InvokeUtil.invokeBeanMethod("pjqsMapper,pjqsOnListPage",wapper.getPage(),inDto);
            } else {
                list = pjqsService.getPjqsOffList(wapper.getPage(),inDto);
            }

        } catch (Exception e) {
            e.printStackTrace();
            return ERROR;
        }
        return SUCCESS(list);
    }

    /**
     * 配件签收保存
     *
     * @return
     */
    @RequestMapping(value = "pjqsSave")
    public ResponseData xchbSave(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        try {
            pjqsService.pjqsSave(wapper.getSysUser(),inDto);
        } catch (Exception e) {
            e.printStackTrace();
            return ERROR;
        }
        return SUCCESS;
    }


}
